 /*
 * Interpolator.cpp
 *
 *  Created on: 31 déc. 2009
 *      Author: math
 */

#include <liblut/core/Interpolator.h>


BoundInterpolator::BoundInterpolator(){
    m_channelInterpolator=ChannelInterpolatorLinear();
}


BoundInterpolator::BoundInterpolator(InterpolatorType inter_type){
    switch (inter_type) {
      case min :
        m_channelInterpolator=ChannelInterpolatorMin();
        break;
      case max :
        m_channelInterpolator=ChannelInterpolatorMax();
        break;
      case linear :
        m_channelInterpolator=ChannelInterpolatorLinear();
        break;
      default :
        m_channelInterpolator=ChannelInterpolatorLinear();
        break;
    }
}

BoundInterpolator::channelInterType
BoundInterpolator::getChannelInterpolator() const {
    return m_channelInterpolator;
}

void
BoundInterpolator::setChannelInterpolator(channelInterType interpolator) {
    m_channelInterpolator=interpolator;
}

LutColor
BoundInterpolator::interpole(const LutBound &B1, const LutBound &B2,
                             double pos){
    double infAtt=B1.getValue();
    double supAtt=B2.getValue();
    double t=(pos-infAtt)/(supAtt-infAtt);
    int C1=m_channelInterpolator(B1.getColor().getC1(),
                                 B2.getColor().getC1(),
                                 t);
    int C2=m_channelInterpolator(B1.getColor().getC2(),
                                 B2.getColor().getC2(),
                                 t);
    int C3=m_channelInterpolator(B1.getColor().getC3(),
                                 B2.getColor().getC3(),
                                 t);
    LutColor tempLutColor = LutColor(C1,C2,C3,B1.getColor().getColorSpace());
    return tempLutColor;
}


